/**

This file is part of MaCI/GIMnet.

MaCI/GIMnet is free software: you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published 
by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.

MaCI/GIMnet is distributed in the hope that it will be useful, but WITHOUT 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with GIMnet. (See COPYING.LESSER) If not, see 
<http://www.gnu.org/licenses/>.

**/
#ifndef _RANGING_FILE_WRITER_HPP
#define _RANGING_FILE_WRITER_HPP

#include "owndebug.h"
#include <string>
#include "RangingData.hpp"
#include "RangingClient.hpp"
struct TRangingHeader{
  TRangingHeader(float aMaxDistance= 0.0,
                 float aMinDistance= 0.0,
                 float aPositionX = 0.0,
                 float aPositionY = 0.0,
                 float aPositionZ = 0.0,
                 float aHeading = 0.0)
    :maxDistance(aMaxDistance),
     minDistance(aMinDistance),
     positionX(aPositionX),
     positionY(aPositionY),
     positionZ(aPositionZ),
     heading(aHeading){}

  float maxDistance;
  float minDistance;
  float positionX;
  float positionY;
  float positionZ;
  float heading;
 
};


class CRangingFileWriter{
public:
  /**
   * Constructor
   */
  CRangingFileWriter();

  /**
   * Destructor
   */
  ~CRangingFileWriter();

  /**
   * Opens file with wanted filename
   */
  void OpenFile(std::string aFileName,
                std::string aMaCIGroup,
                std::string aInstanceName,
                TRangingHeader aHeader);

  /**
   * Closes the file
   */
  void CloseFile();

  /**
   * Writes a line of position information
   *
   * @param[in]    position information structure which have a measurement
   * @return       true if line succesfully writed (==file opened)
   */
  bool WriteLine(MaCI::Ranging::TDistanceHeader &aHeader,
                 MaCI::Ranging::TDistanceArray &aArray,
                 MaCI::Common::TTimestamp &aTimestamp);

  
private:
  FILE *iFile;

  CRangingFileWriter(const CRangingFileWriter&)
    :iFile(NULL){}

  CRangingFileWriter &operator=(const  CRangingFileWriter&){return *this;}

};
#endif ///< _RANGING_FILE_WRITER_HPP
